﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using UnityEngine;

public enum PARAMTYPE //具体数值
{
    [Description("万分比")]
    PERCENT = 0,//
    [Description("具体数值")]
    NUMVALUE = 1,//
    [Description("公式")]
    FORMULA = 2,//
}

[Serializable]
public class SmartTransform
{
    public Vector3 m_Position;
    public Vector3 m_Forward;

    public SmartTransform()
    {

    }
    public SmartTransform(Vector3 position, Vector3 forward)
    {
        m_Position = position;
        m_Forward = forward;
    }

    public float GetAngel()
    {
        return CommonTools.GetAnglePlane(Vector3.zero, m_Forward);
    }
}



[Serializable]
public struct SmartSection
{
    public float m_fMin;
    public float m_fMax;

    public void DoInit(float fMin, float fMax)
    {
        m_fMin = fMin;
        m_fMax = fMax;
    }
    public float Random()
    {
        return CommonTools.RandomFloat(m_fMin, m_fMax);
    }
    public float Min
    {
        get
        {
            return m_fMin;
        }
        set
        {
            m_fMin = value;
        }
    }
    public float Max
    {
        get
        {
            return m_fMax;
        }
        set
        {
            m_fMax = value;
        }
    }
}

[Serializable]
public struct SmartProgress
{
    float m_fCur;
    float m_fMax;

    public float Cur
    {
        get { return m_fCur; }
        set { m_fCur = value; }
    }
    public float Max
    {
        get { return m_fMax; }
        set { m_fMax = value; }
    }
    public void DoReset(float fMax)
    {
        DoReset(fMax, fMax);

    }
    public void DoReset(float fCur, float fMax)
    {
        m_fCur = fCur;
        m_fMax = fMax;
    }

    public void DoReset(bool bClear = true)
    {
        if (bClear)
            m_fCur = 0;
        else
            m_fCur = m_fCur % m_fMax;
    }

    public void DoZero()
    {
        m_fCur = 0;
    }

    public void DoFull()
    {
        m_fCur = m_fMax;
    }
    public bool IsFull()
    {
        if (m_fMax <= m_fCur)
            return true;
        return false;
    }
    Action<int> m_OnFullCallBack;
    public void SetFullCallBack(Action<int> OnFullCallBack)
    {
        m_OnFullCallBack = OnFullCallBack;

    }
    public void DoAdd(float fValue, bool bClear = true)
    {
        m_fCur += fValue;
        if (bClear)
        {
            if (m_fCur > m_fMax)
                m_fCur = m_fMax;
            if (m_fCur < 0)
                m_fCur = 0;
        }
        else
        {
            if (m_fCur > m_fMax)
            {
                int num = (int)(m_fCur / m_fMax); // 获取满了几次
                m_OnFullCallBack(num);
            }
            m_fCur = m_fCur % m_fMax;
            if (m_fCur < 0)
                m_fCur = 0;
        }
    }
    public bool DoUpdate(float fSpeed)
    {
        m_fCur += fSpeed * Time.deltaTime;
        if (m_fCur >= m_fMax)
            return true;
        if (m_fCur < 0)
            m_fCur = 0;
        return false;
    }
    public float GetScale()
    {
        if (m_fMax <= 0)
            return 0;
        return m_fCur / m_fMax;
    }
    public bool DoRaise(float fValue, ref int num)
    {
        if (m_fMax < 0)
            return false;
        m_fCur += fValue;
        if (m_fCur >= m_fMax)
        {
            num = (int)m_fCur / (int)m_fMax;
            m_fCur = m_fCur % m_fMax;
            return true;
        }
        return false;
    }
}

public struct SmartCounter
{
    int m_nCur;
    int m_nMax;
    public void DoReset(int fMax)
    {
        m_nMax = fMax;
        m_nCur = 0;
    }

    public bool IsMax()
    {
        return m_nCur >= m_nMax;
    }
    public bool IsZero()
    {
        return m_nCur <= 0;
    }
    public bool DoSet(int nValue)
    {
        if (m_nMax < 0)
            return false;
        m_nCur = nValue;
        if (m_nCur >= m_nMax)
        {
            m_nCur = m_nMax;
            return true;
        }
        return false;
    }
    public bool DoRaise(int nValue, ref int num)
    {
        if (m_nMax < 0)
            return false;
        m_nCur += nValue;
        if (m_nCur >= m_nMax)
        {
            num = m_nCur / m_nMax;
            m_nCur = m_nCur % m_nMax;
            return true;
        }
        return false;
    }
    public bool DoAdd(int nValue)
    {
        if (m_nMax < 0)
            return false;
        m_nCur += nValue;
        if (m_nCur >= m_nMax)
        {
            m_nCur = m_nMax;
            return true;
        }
        return false;
    }
    public bool DoReduce(int nValue)
    {
        if (m_nMax < 0)
            return false;
        m_nCur -= nValue;
        if (m_nCur <= 0)
            return true;
        return false;
    }
    public void DoRestart()
    {
        m_nCur = 0;
    }

    public void DoFull()
    {
        m_nCur = m_nMax;
    }

    public int Cur()
    {
        return m_nCur;
    }
    public int Max()
    {
        return m_nMax;
    }
    public float GetPrecent()
    {
        return (float)m_nCur / (float)m_nMax;
    }
    public override string ToString()
    {
        return m_nCur.ToString() + "/" + m_nMax.ToString();
    }

    public bool IsValid()
    {
        return m_nMax > 0;
    }

    public void DoClose()
    {
        m_nMax = 0;
    }
}


[Serializable]
public struct SmartProperty
{
    float m_fCur;
    float m_fMin;
    float m_fMax;
    public void DoReset(float fCur, float fMax, float fMin = 0)
    {
        m_fCur = fCur;
        m_fMax = fMax;
        m_fMin = 0;

    }
    public void DoReset()
    {
        m_fCur = m_fMax;
    }
    //  如果超过上限，返回1，低于下限返回-1
    public bool IsMax()
    {
        return m_fCur >= m_fMax;
    }
    public void DoSetPercent(float value)
    {
        if (m_fMax > 0)
        {
            m_fCur = value * m_fMax / 100;
        }
    }
    public void DoSet(float value)
    {
        if (m_fMax > 0)
        {
            m_fCur = value;
        }
    }
    public float DoAddPercent(float value)
    {
        if (m_fMax > 0)
        {
            return DoAdd(value * m_fMax / 100);
        }
        return 0;
    }
    public float DoAdd(float fValue)
    {
        m_fCur += fValue;
        if (m_fMax < 0)
            return 0;
        if (m_fCur > m_fMax)
        {
            m_fCur = m_fMax;
            return 1;
        }
        if (m_fCur < 0)
        {
            m_fCur = 0;
            return -1;
        }
        return 0;
    }
    public float GetValue()
    {
        return m_fCur;
    }
    public float GetMax()
    {
        return m_fMax;
    }
    public float GetScale()
    {
        return m_fCur / m_fMax;
    }

    public float GetPercent()
    {
        return (int)(m_fCur / m_fMax * 100);
    }

    public override string ToString()
    {
        return string.Format("{0}/{1}", (int)m_fCur, (int)m_fMax);
    }
}


[Serializable]
public class SmartTimer
{
    public float m_fTimer = 0;
    public float m_fMaxTimer = -1;// 如果最大值是-1，就是递增计时器，永远不会自动停,大与0，就是递减计时器，会有update的返回false，
    public bool m_bActive = false;
    public SmartTimer Copy()
    {
        var value = new SmartTimer();
        value.m_fMaxTimer = m_fMaxTimer;
        value.m_fTimer = m_fTimer;
        value.m_bActive = m_bActive;
        return value;
    }
    public bool IsActive()
    {
        return m_bActive;
    }
    public float GetMax()
    {
        return m_fMaxTimer;
    }
    public float GetTimer()
    {
        return m_fTimer;
    }
    public float GetScale()
    {
        if (m_fMaxTimer > 0)
            return m_fTimer / m_fMaxTimer;
        return 0;
    }
    float m_fLastTime = 0;
    float m_fDeltaTime = 0;
    public float GetDelta(bool bReal = false)
    {
        if (bReal)
            return m_fDeltaTime;
        return Time.deltaTime;
    }
    ModifyBase m_Modify = new ModifyBase();
    public ModifyBase Modify
    {
        get { return m_Modify; }
    }
    public bool DoUpdate(float fTimeScale = 1, bool bReal = false)
    {
        if (!m_bActive)
            return false;
        // 这里自己管理帧数的计算，不知道为什么 time.deltatime的值总是跟真实的数据不一样，只能自己管理了
        //m_fDeltaTime = (Time.realtimeSinceStartup - m_fLastTime) * Time.timeScale;
        m_fDeltaTime = (Time.realtimeSinceStartup - m_fLastTime) * Time.timeScale;
        m_fLastTime = Time.realtimeSinceStartup;
        int cur = (int)m_fTimer;
        if (m_fMaxTimer < 0)
        {
            m_fTimer += GetDelta(bReal) * fTimeScale;
            if (cur != (int)m_fTimer)
                Modify.MakeModify();
            return false;
        }
        else if (m_fMaxTimer >= 0)
        {
            if (m_fTimer >= 0)
            {
                m_fTimer -= GetDelta(bReal) * fTimeScale;
                if (cur != (int)m_fTimer)
                    Modify.MakeModify();
                if (m_fTimer < 0)
                {
                    Modify.MakeModify();
                    m_bActive = false;
                    //m_fTimer = 0;
                    return true;
                }
            }
        }
        return false;
    }
    public void DoStop()
    {
        m_bActive = false;
    }

    public void DoClose()
    {
        m_fTimer = 0;
        m_bActive = false;
    }
    public void DoReset()
    {
        if (m_fMaxTimer > 0)
            m_fTimer = m_fMaxTimer;
        else
            m_fTimer = 0;
        m_bActive = true;
        m_fLastTime = Time.realtimeSinceStartup;
        Modify.MakeModify();
    }
    public bool DoRestart()
    {
        if (m_fMaxTimer > 0)
        {
            m_fTimer = m_fMaxTimer + m_fTimer;
            if (m_fTimer < 0)
                return true;
        }
        else
            m_fTimer = 0;
        m_bActive = true;
        m_fLastTime = Time.realtimeSinceStartup;
        return false;
    }
    public void DoReset(float fTime)
    {
        m_fMaxTimer = fTime;
        DoReset();
    }

    public void SetData(float fTime)
    {
        m_fTimer = fTime;
        m_bActive = true;
        m_fLastTime = Time.realtimeSinceStartup;
    }
    public void SetData(float fTime, float fMaxTime)
    {
        m_fTimer = fTime;
        m_fMaxTimer = fMaxTime;
        m_bActive = true;
        m_fLastTime = Time.realtimeSinceStartup;
    }

    public override string ToString()
    {
        return m_fTimer.ToString() + "/" + m_fMaxTimer.ToString();
    }

    public void Normalize()
    {
        if (m_fMaxTimer > 0)
        {

            if (m_fTimer > m_fMaxTimer)
                m_fTimer = m_fMaxTimer;
            if (m_fTimer < 0)
                m_fTimer = 0;
        }
    }

    public void SetMax(float value)
    {
        m_fMaxTimer = value;
    }
}


[Serializable]
public class SmartParam
{
    [NonSerialized]
    public string m_strData = "";

    public string m_strParam = "";
    [NonSerialized]
    public float m_fValue;
    [NonSerialized]
    public int m_nValue;
    [NonSerialized]
    public string m_strValue = "";
    [NonSerialized]
    List<int> m_intList = new List<int>();
    [NonSerialized]
    List<long> m_longList = new List<long>();
    [NonSerialized]
    List<string> m_strList = new List<string>();
    [NonSerialized]
    float m_fOffset = 0;
    public bool IsEmptyString()
    {
        if (m_strValue == "0" || m_strValue == "")
            return true;
        return false;
    }
    public SmartParam(string param)
    {
        m_strParam = param;
    }
    public SmartParam()
    {
        m_strParam = "";
    }
    public SmartParam(int nValue)
    {
        m_strParam = nValue.ToString();
    }
    public SmartParam(float fValue)
    {
        m_strParam = fValue.ToString();
    }
    #region 获取参数值得接口
    enum ValueType
    {
        Error,
        Value,      // 数值
        Formula,    // 公式
    }
    bool m_bInited = false;
    public SmartParam Copy()
    {
        SmartParam param = new SmartParam();
        param.m_strParam = m_strParam;
        param.m_strData = m_strData;
        param.m_nValue = m_nValue;
        param.m_fValue = m_fValue;
        param.m_strValue = m_strValue;
        param.m_bInited = true;


        return param;
    }

    static char[] keyOffset = new char[] { '|', ',' };
    static string strOffset = "|,";

    public void DoInit(Dictionary<string, string> keyDic)
    {
        m_strList.Clear();
        m_intList.Clear();
        m_longList.Clear();
        //if (m_strParam.IndexOf(',') > 0)
        //{
        //    LogMgr.Instance().LogError("{0} value={1} ", ToString(), m_strParam);
        //    throw new Exception();
        //}
        if (!string.IsNullOrEmpty(m_strParam) && m_strParam.IndexOf(strOffset) > 0)
        {

            string[] data = m_strParam == null ? null : m_strParam.Split(keyOffset, StringSplitOptions.RemoveEmptyEntries);
            if (data != null && data.Length > 0) // 如果这个值小于1,就不管了
            {
                m_strData = data[0];
                //m_strList = new List<string>(data);
                if (!float.TryParse(data[1], out m_fOffset))
                    m_fOffset = 0;
            }
            else
            {
                m_strData = m_strParam;
            }
        }
        else
        {
            m_strData = m_strParam;
        }

        m_fValue = GetValueFloat(keyDic, m_strData) + m_fOffset;
        m_nValue = GetValueInt(keyDic, m_strData) + (int)m_fOffset;
        m_strValue = GetValueString(keyDic, m_strData);
        if (!string.IsNullOrEmpty(m_strValue))
            m_strList = StringTools.GetStringList(m_strValue);
        m_bInited = true;
        if (m_strError != "")
        {
            ErrorManager.Instance().ShowError(m_strError);
            //SG.LogMgr.Instance().Log(m_strError);
        }
        m_strError = "";


    }

    // 内部调用，获取指定
    static string m_strError = "";
    static ValueType GetValueString(string strParam, Dictionary<string, string> keyDic, ref string strValue)
    {
        var curType = ValueType.Error;
        if (strParam == null || strParam == "")
        {
            strValue = "";
            curType = ValueType.Value;
        }
        else
        if (strParam.Contains("#")) // 如果有#好，就是从表里读数据
        {
            strParam = strParam.Replace("#", "");
            if (keyDic != null && keyDic.ContainsKey(strParam))
            {
                strValue = keyDic[strParam];
            }
            else
            {
                strValue = "";
            }
            //strParam = StringTools.StringPool.GetTureKeyFromPool(strParam);
            curType = ValueType.Value;
        }
        else if (strParam.Contains("$")) // 如果有$好，就是从公式表里算
        {
            strParam = strParam.Replace("$", "");
            //strParam = StringTools.StringPool.GetTureKeyFromPool(strParam);
            curType = ValueType.Formula;
        }
        else
        {
            strValue = strParam;
            return ValueType.Value;
        }
        if (keyDic == null)
        {
            strValue = "";
            return ValueType.Value;
        }
        if (strParam != "" && !keyDic.TryGetValue(strParam, out strValue))
        {
            strValue = null;
            m_strError = "没有找到key=" + strParam + "的值,此值暂时不用或漏填";
        }
        return curType;
    }

    //对外接口，获取字典里的字符串数据
    public static string GetValueString(Dictionary<string, string> keyDic, string strParam)
    {
        string strValue = "";
        switch (GetValueString(strParam, keyDic, ref strValue))
        {
            case ValueType.Value:
                break;
            case ValueType.Formula:
                break;
        }

        return strValue;
    }
    //对外接口，获取字典里的浮点值
    public static float GetValueFloat(Dictionary<string, string> keyDic, string strParam)
    {
        string strValue = "";
        switch (GetValueString(strParam, keyDic, ref strValue))
        {
            case ValueType.Value:
                {
                    float v = 0;
                    if (float.TryParse(strValue, out v))
                        return v;
                }
                break;
            case ValueType.Formula:
                break;
        }

        return 0;
    }
    //对外接口，获取字典里的整型
    public static int GetValueInt(Dictionary<string, string> keyDic, string strParam)
    {
        string strValue = "";
        switch (GetValueString(strParam, keyDic, ref strValue))
        {
            case ValueType.Value:
                {
                    int v = 0;
                    if (int.TryParse(strValue, out v))
                        return v;
                }
                break;
            case ValueType.Formula:
                break;
        }
        return 0;
    }
    #endregion

    // 获取字符串里的整型数据列表
    public List<int> GetIntList()
    {

        if (m_intList.Count > 0)
            return m_intList;
        for (int i = 0; i < m_strList.Count; ++i)
            m_intList.Add(int.Parse(m_strList[i]));
        return m_intList;
    }
    // 获取字符串里的长整型数据列表
    public List<long> GetLongList()
    {

        if (m_longList.Count > 0)
            return m_longList;
        for (int i = 0; i < m_strList.Count; ++i)
            m_longList.Add(long.Parse(m_strList[i]));
        return m_longList;
    }
    // 获取字符串里的字符串型数据列表
    public List<string> GetStringList()
    {
        if (!m_bInited)
            XKLog.LogError("有SmartParam没有初始化就用了");
        return m_strList;
    }

    // 参数字符串生成数据字典

}


[Serializable]
public class SmartValue
{
    int m_nSeed = 0;
    float m_fValue1;
    float m_fValue2;
    public SmartValue()
    {
    }
    public SmartValue(float fData)
    {
        SetValue(fData);
    }
    public SmartValue(int fData)
    {
        SetValue(fData);
    }

    public long GetLong()
    {
        return (long)(m_fValue1 + m_fValue2);
    }
    public int GetInt()
    {
        return (int)(m_fValue1 + m_fValue2);
    }
    public float GetFloat()
    {
        return m_fValue1 + m_fValue2;
    }
    public void SetValue(float fData)
    {
        m_nSeed = CommonTools.RandomInt(0, 100000);
        m_fValue1 = CommonTools.RandomFloat(-m_nSeed, m_nSeed);
        m_fValue2 = fData - m_fValue1;
    }
    public void SetValue(int nData)
    {
        m_nSeed = CommonTools.RandomInt(0, 100000);
        m_fValue1 = CommonTools.RandomInt(-1000, 1000);
        m_fValue2 = nData - m_fValue1;
    }
    #region    float 2 smartValue
    public static SmartValue operator *(float a, SmartValue b)
    {
        SmartValue sv = new SmartValue();
        sv.SetValue(a * b.GetFloat());
        return sv;
    }

    public static SmartValue operator /(float a, SmartValue b)
    {
        SmartValue sv = new SmartValue();
        sv.SetValue(a / b.GetFloat());
        return sv;
    }
    public static SmartValue operator -(float a, SmartValue b)
    {
        SmartValue sv = new SmartValue();
        sv.SetValue(a - b.GetFloat());
        return sv;
    }

    public static SmartValue operator +(float a, SmartValue b)
    {
        SmartValue sv = new SmartValue();
        sv.SetValue(a + b.GetFloat());
        return sv;
    }
    #endregion



    #region smartValue * float
    public static SmartValue operator *(SmartValue a, float b)
    {
        SmartValue sv = new SmartValue();
        sv.SetValue(a.GetFloat() * b);
        return sv;
    }

    public static SmartValue operator /(SmartValue a, float b)
    {
        SmartValue sv = new SmartValue();
        sv.SetValue(a.GetFloat() / b);
        return sv;
    }
    public static SmartValue operator -(SmartValue a, float b)
    {
        SmartValue sv = new SmartValue();
        sv.SetValue(a.GetFloat() - b);
        return sv;
    }

    public static SmartValue operator +(SmartValue a, float b)
    {
        SmartValue sv = new SmartValue();
        sv.SetValue(a.GetFloat() + b);
        return sv;
    }
    #endregion
    #region smartvalue 2 smartvalue
    public static SmartValue operator *(SmartValue a, SmartValue b)
    {
        SmartValue sv = new SmartValue();
        sv.SetValue(a.GetFloat() * b.GetFloat());
        return sv;
    }

    public static SmartValue operator /(SmartValue a, SmartValue b)
    {
        SmartValue sv = new SmartValue();
        sv.SetValue(a.GetFloat() / b.GetFloat());
        return sv;
    }
    public static SmartValue operator -(SmartValue a, SmartValue b)
    {
        SmartValue sv = new SmartValue();
        sv.SetValue(a.GetFloat() - b.GetFloat());
        return sv;
    }

    public static SmartValue operator +(SmartValue a, SmartValue b)
    {
        SmartValue sv = new SmartValue();
        sv.SetValue(a.GetFloat() + b.GetFloat());
        return sv;
    }
    #endregion
}

#region 为了防止数值来回的copy造成数据冗余以及保证玩家身上只需要保持一份数据备份
//数据修饰器，用来封存一个数值
public class IntModifier
{

    public int Value;
    public bool enable = true;
    public PARAMTYPE pType = PARAMTYPE.NUMVALUE;
    public bool isCache = false;
    public bool isSprite = false;
    public IntModifier(int smartValue, PARAMTYPE pARAMTYPE = PARAMTYPE.NUMVALUE, bool cache = false, bool sprite = false)
    {
        this.Value = smartValue;
        this.isCache = cache;
        this.isSprite = sprite;
        this.pType = pARAMTYPE;
    }

    public IntModifier Copy()
    {
        IntModifier intModifier = new IntModifier(this.Value, this.pType, this.isCache, this.isSprite);
        intModifier.enable = enable;
        return intModifier;
    }
}

//数据收集器，用于收集数据
public class IntModifierCollector
{
    public int TotalValue { get; private set; }
    public List<IntModifier> Modifiers { get; set; } = new List<IntModifier>();

    public void AddModifiers(List<IntModifier> intModifiers)
    {
        foreach (var modifier in intModifiers)
        {
            AddModifier(modifier.Copy());
        }
    }

    public int AddModifier(IntModifier modifier)
    {
        Modifiers.Add(modifier);
        Update();
        return TotalValue;
    }

    public int ClearModifier()
    {
        Modifiers.Clear();
        Update();
        return TotalValue;
    }

    public int RemoveModifier(IntModifier modifier)
    {
        if (Modifiers.Contains(modifier))
        {
            Modifiers.Remove(modifier);
            Update();
        }
        return TotalValue;
    }

    public int ChangeModifier(IntModifier modifier, bool enable = true)
    {
        foreach (var md in Modifiers)
        {
            if (md == modifier)
            {
                md.enable = enable;
                break;
            }
        }
        Update();
        return TotalValue;
    }

    public int Update()
    {
        TotalValue = 0;
        foreach (var item in Modifiers)
        {
            TotalValue += item.Value;
        }
        return TotalValue;
    }
}

public class IntNumeric
{
    public SmartValue Value = new SmartValue();
    public SmartValue baseValue = new SmartValue();//基础属性
    public int addValue = 0;//附加属性
    public int addSpValue = 0;//附加作用于精怪的属性
    public PARAMTYPE cupType = PARAMTYPE.NUMVALUE;//默认数值计算
    public int toValue = 0;
    public int add { get; private set; }
    public int pctAdd { get; private set; }
    public int CacheAdd { get; private set; }
    public int CachePctAdd { get; private set; }
    public int spriteAdd { get; private set; }
    public int spritePctAdd { get; private set; }
    private IntModifierCollector AddCollector { get; } = new IntModifierCollector();
    private IntModifierCollector PctAddCollector { get; } = new IntModifierCollector();

    private IntModifierCollector CacheAddCollector { get; } = new IntModifierCollector();
    private IntModifierCollector CachePctAddCollector { get; } = new IntModifierCollector();
    private IntModifierCollector spriteAddCollector { get; } = new IntModifierCollector();
    private IntModifierCollector spritePctAddCollector { get; } = new IntModifierCollector();
    public void Initialize()
    {
        add = pctAdd = CacheAdd = CachePctAdd = spriteAdd = spritePctAdd = 0;
        baseValue.SetValue(0);
        Value.SetValue(0);
    }

    public IntNumeric DeepCopy()
    {
        IntNumeric intNumeric = new IntNumeric();
        intNumeric.cupType = cupType;
        intNumeric.baseValue.SetValue(this.baseValue.GetInt());
        intNumeric.toValue = this.toValue;
        intNumeric.addValue = this.addValue;
        intNumeric.addSpValue = this.addSpValue;
        intNumeric.AddCollector.AddModifiers(this.AddCollector.Modifiers);
        intNumeric.PctAddCollector.AddModifiers(this.PctAddCollector.Modifiers);
        intNumeric.CacheAddCollector.AddModifiers(this.CacheAddCollector.Modifiers);
        intNumeric.CachePctAddCollector.AddModifiers(this.CachePctAddCollector.Modifiers);
        intNumeric.spriteAddCollector.AddModifiers(this.spriteAddCollector.Modifiers);
        intNumeric.spritePctAddCollector.AddModifiers(this.spritePctAddCollector.Modifiers);
        intNumeric.RefshValue();
        intNumeric.Update();
        return intNumeric;
    }

    public int GetAtbValue()
    {
        if (add > 0)
        {
            return add;
        }
        return baseValue.GetInt();
    }
    //如果直接设置了数值则直接使用设置的数值
    public void SetToValue(int num)
    {
        toValue = num;
    }



    public int GetParamValue(bool isSprite = false)
    {
        if (toValue != 0)
        {
            return toValue;
        }
        if (isSprite)
        {
            if (cupType == PARAMTYPE.NUMVALUE)
            {
                int value1 = baseValue.GetInt();
                int value2 = Mathf.CeilToInt(value1 * ((10000 + pctAdd + CachePctAdd + spritePctAdd) * TypeDefine.CommonScale) + add + CacheAdd + spriteAdd + addValue + addSpValue);
                return Convert.ToInt32(value2);
            }
            else
            {
                int value1 = baseValue.GetInt();
                int value2 = (value1 + pctAdd + CachePctAdd + spritePctAdd + add + CacheAdd + spriteAdd + addValue + addSpValue);
                return Convert.ToInt32(value2);
            }

        }
        return Value.GetInt();
    }

    public int GetBase()
    {
        return baseValue.GetInt();
    }

    public void AddAddModifier(IntModifier modifier)
    {
        add = AddCollector.AddModifier(modifier);
        Update();
    }
    public void AddPctAddModifier(IntModifier modifier)
    {
        pctAdd = PctAddCollector.AddModifier(modifier);
        Update();
    }
    public void AddCacheAddModifier(IntModifier modifier)
    {
        CacheAdd = CacheAddCollector.AddModifier(modifier);
        Update();
    }
    public void AddCachePctAddModifier(IntModifier modifier)
    {
        CachePctAdd = CachePctAddCollector.AddModifier(modifier);
        Update();
    }

    public void AddSpriteAddModifier(IntModifier modifier)
    {
        spriteAdd = spriteAddCollector.AddModifier(modifier);
    }
    public void AddSpritePctAddModifier(IntModifier modifier)
    {
        spritePctAdd = spritePctAddCollector.AddModifier(modifier);
    }

    public void RemoveCacheAddModifier(IntModifier modifier)
    {
        CacheAdd = CacheAddCollector.RemoveModifier(modifier);
        Update();
    }
    public void RemoveCachePctAddModifier(IntModifier modifier)
    {
        CachePctAdd = CachePctAddCollector.RemoveModifier(modifier);
        Update();
    }
    public void RemoveAddModifier(IntModifier modifier)
    {
        add = AddCollector.RemoveModifier(modifier);
        Update();
    }
    public void RemovePctAddModifier(IntModifier modifier)
    {
        pctAdd = PctAddCollector.RemoveModifier(modifier);
        Update();
    }

    public void RemoveSpriteAddModifier(IntModifier modifier)
    {
        spriteAdd = spriteAddCollector.RemoveModifier(modifier);
    }
    public void RemoveSpritePctAddModifier(IntModifier modifier)
    {
        spritePctAdd = spritePctAddCollector.RemoveModifier(modifier);
    }

    public void RemoveModifier(IntModifier intModifier)
    {
        PARAMTYPE pType = intModifier.pType; bool isCache = intModifier.isCache; bool isSprite = intModifier.isSprite;
        if (pType == PARAMTYPE.NUMVALUE)
        {
            if (isSprite)
            {
                RemoveSpriteAddModifier(intModifier);
            }
            else if (isCache)
            {
                RemoveCacheAddModifier(intModifier);
            }
            else
            {
                RemoveAddModifier(intModifier);
            }
        }
        else
        {
            if (isSprite)
            {
                RemoveSpritePctAddModifier(intModifier);
            }
            else if (isCache)
            {
                RemoveCachePctAddModifier(intModifier);
            }
            else
            {
                RemovePctAddModifier(intModifier);
            }
        }
    }

    public void RefshAddValue(int num, bool isSprite = false)
    {
        if (isSprite)
        {
            addSpValue = num;
        }
        else
        {
            addValue = num;
            Update();
        }
    }

    public IntModifier AddModifier(int num, PARAMTYPE pType = PARAMTYPE.NUMVALUE, bool isCache = false, bool isSprite = false, bool isSpirteBag = false)
    {
        if (isSpirteBag)
        {
            int addNum = num;
            if (cupType == PARAMTYPE.NUMVALUE)
            {
                if (pType == PARAMTYPE.PERCENT)
                {
                    addNum = Mathf.CeilToInt(GetBase() * Math.Abs(num) * TypeDefine.CommonScale);
                    if (num < 0)
                    {
                        addNum = addNum * -1;
                    }
                }
            }
            if (isSprite)
            {
                addSpValue += addNum;
            }
            else
            {
                addValue += addNum;
                Update();
            }
            return null;
        }
        IntModifier intModifier = new IntModifier(num, pType, isCache, isSprite);
        if (pType == PARAMTYPE.NUMVALUE)
        {
            if (isSprite)
            {
                AddSpriteAddModifier(intModifier);
            }
            else if (isCache)
            {
                AddCacheAddModifier(intModifier);
            }
            else
            {
                AddAddModifier(intModifier);
            }
        }
        else
        {
            if (isSprite)
            {
                AddSpritePctAddModifier(intModifier);
            }
            else if (isCache)
            {
                AddCachePctAddModifier(intModifier);
            }
            else
            {
                AddPctAddModifier(intModifier);
            }
        }
        return intModifier;
    }

    public void ClearCache()
    {
        CachePctAdd = CachePctAddCollector.ClearModifier();
        CacheAdd = CacheAddCollector.ClearModifier();
        Update();
    }

    public void RefshValue()
    {
        CachePctAdd = CachePctAddCollector.Update();
        CacheAdd = CacheAddCollector.Update();
        add = AddCollector.Update();
        pctAdd = PctAddCollector.Update();
        spriteAdd = spriteAddCollector.Update();
        spritePctAdd = spritePctAddCollector.Update();
    }

    public float show = 0;

    public void Update()
    {
        var value1 = baseValue.GetInt();
        if (cupType == PARAMTYPE.NUMVALUE)
        {
            int value2 = Mathf.CeilToInt(value1 * ((10000 + pctAdd + CachePctAdd) * TypeDefine.CommonScale) + add + CacheAdd + addValue);
            Value.SetValue(value2);
            show = value2;
        }
        else
        {
            int value2 = (value1 + pctAdd + CachePctAdd + add + CacheAdd + addValue);
            Value.SetValue(value2);
            show = value2;
        }
    }
}

#endregion